package com.oilsection.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.oilsection.demo.controller.req.JcdUpdateLocationReq;
import com.oilsection.demo.controller.req.JzUpdateLocationReq;
import com.oilsection.demo.dao.GetJzListSourceDao;
import com.oilsection.demo.dao.GetQkListSourceDao;
import com.oilsection.demo.mapper.JcdMapper;
import com.oilsection.demo.mapper.JzMapper;
import com.oilsection.demo.po.Jcd;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class JcdService {
    private final GetQkListSourceDao kqListSourceDao;
    private final GetJzListSourceDao jzListSourceDao;

    private final JcdMapper jcdMapper;

    public void updateLocation(JcdUpdateLocationReq req) {
        jcdMapper.updateLocation(req.getJcdId(), req.getJcdXpoint(), req.getJcdYpoint());
    }

    public List<Jcd> list(Jcd jcd) {
        List<Jcd> jcds = jcdMapper.selectList(new LambdaQueryWrapper<Jcd>().eq(Jcd::getKqId, jcd.getKqId()));
        for (Jcd jcd1 : jcds) {
            jcd1.setKqName(kqListSourceDao.findById(jcd1.getKqId()).get().getName());
            jcd1.setJzName(jzListSourceDao.findById(jcd1.getJzId()).get().getJzName());
        }

        return jcds;
    }
}
